package cn.itsource.easyexcel.write;

import cn.itsource.constant.Constant;
import cn.itsource.util.GenerateUserUtil;
import cn.itsource.vo.User;
import com.alibaba.excel.EasyExcel;

import java.io.File;

public class WriteDemo8 {
    public static void main(String[] args) {
        //先创建一个excel文件
        String filename = Constant.BATH_URL + "user8.xlsx";
        // 向Excel中写入数据
        EasyExcel.write(filename, User.class)
                .sheet("用户信息")
                .doWrite(GenerateUserUtil.getUserData());


        //在已有的excel文件中   追加数据
        File file = new File(Constant.BATH_URL + "user8.xlsx");
        File tempFile = new File(Constant.BATH_URL + "temp.xlsx");
        EasyExcel.write(file, User.class)
                .withTemplate(file).file(tempFile)
                .sheet(1,"用户信息2")//sheet的编号和sheet的名字   需要同时传入才会创建sheet页
                .doWrite(GenerateUserUtil.getUserData());
    }
}
